//
//  ZSSettingViewController.m
//  ZhuShou
//
//  Created by Dejun Liu on 15/10/28.
//  Copyright © 2015年 jw. All rights reserved.
//

#import "ZSSettingViewController.h"
#import "ZSNoneTableViewCell.h"
#import "ZSSetting.h"
#import "ZSUserAccountTableViewController.h"
#import "ZSHostManageTableViewController.h"
#import "ZSENVTableViewController.h"
#import "ZSSceneTableViewController.h"
#import "ZSDeviceViewController.h"
#import "ZSDefenseTableViewController.h"
#import "ZSUniteTableViewController.h"
#import "ZSCodeTableViewController.h"
#import "ZSUpdateTableViewController.h"
#import "ZSTimingTableViewController.h"
#import "ZSHelpViewController.h"
#import "UIViewController+UIViewController_Extesion.h"

@interface ZSSettingViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *listData;
@property (strong, nonatomic) IBOutlet UIView *tb_header;

@end

@implementation ZSSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置";
    [self initViews];
}

-(void)initViews
{
//    [super initViews];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)
                                                  style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
//    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"ZSNoneTableViewCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
    
    self.tableView.tableHeaderView = self.tb_header;
    
    
    self.listData = [ZSSetting df_list];
    [self.tableView reloadData];
    
    @weakify(self);
    [self.tb_header addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        @strongify(self);
        [self br_pushViewControllerWithClassName:@"ZSUserAccountTableViewController"];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.listData.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 62.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:0 reuseIdentifier:identifier];
    }
    cell.textLabel.text = @"";
    
    ZSSetting *setting = [self.listData objectAtIndex:indexPath.row];
    cell.textLabel.text = setting.title;
    cell.imageView.image = [UIImage imageNamed:setting.iconName];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ZSSetting *setting = [self.listData objectAtIndex:indexPath.row];
    switch (setting.type) {
        case ZSSettingTypeHost:
            [self br_pushViewControllerWithClassName:@"ZSHostManageTableViewController" withTitle:setting.title];
            break;
        case ZSSettingTypeENV:
            [self br_pushViewControllerWithClassName:@"ZSENVTableViewController" withTitle:setting.title];
            break;
        case ZSSettingTypeScene:
            [self br_pushViewControllerWithClassName:@"ZSSceneTableViewController" withTitle:setting.title];
            break;
        case ZSSettingTypeDevice:
            [self br_pushViewControllerWithClassName:@"ZSDeviceViewController" withTitle:setting.title];
            break;
        case ZSSettingTypeDefense:
            [self br_pushViewControllerWithClassName:@"ZSDefenseTableViewController" withTitle:setting.title];
            break;
        case ZSSettingTypeUnite:
            [self br_pushViewControllerWithClassName:@"ZSUniteTableViewController" withTitle:setting.title];
            break;
        case ZSSettingTypeCode:
            [self br_pushViewControllerWithClassName:@"ZSCodeTableViewController" withTitle:setting.title];
            break;
        case ZSSettingTypeUpdate:
            [self br_pushViewControllerWithClassName:@"ZSUpdateTableViewController" withTitle:setting.title];
            break;
        case ZSSettingTypeTiming:
            [self br_pushViewControllerWithClassName:@"ZSTimingTableViewController" withTitle:setting.title];
            break;
        case ZSSettingTypeHelp:
            [self br_pushViewControllerWithClassName:@"ZSHelpViewController" withTitle:setting.title];
            break;
        default:
            break;
    }
}

#pragma mark Actions

- (IBAction)didTapTableViewHeader:(id)sender {
    
}


@end
